package org.jeecg.modules.quartz.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.gongqiang.mapper.SerialNumberMapper;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 示例带参定时任务
 * 
 * @Author Scott
 */
@Slf4j
public class SerialNumber implements Job {

	/**
	 * 若参数变量名修改 QuartzJobController中也需对应修改
	 */
	private String parameter;

	@Resource
	private SerialNumberMapper serialNumberMapper;

	public void setParameter(String parameter) {
		this.parameter = parameter;
	}

	@Override
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
		log.info(" SerialNumber Execution key："+jobExecutionContext.getJobDetail().getKey());
		log.info( String.format("welcome %s! Jeecg-Boot 带参数定时任务 SerialNumber !   时间:" + DateUtils.now(), this.parameter));
		//查询所有目前有效但是结束时间小于当天的
		LambdaQueryWrapper<org.jeecg.modules.gongqiang.entity.SerialNumber> querySerialNumber = new LambdaQueryWrapper<org.jeecg.modules.gongqiang.entity.SerialNumber>();
		querySerialNumber.le(org.jeecg.modules.gongqiang.entity.SerialNumber::getEndTime, new Date());
		querySerialNumber.eq(org.jeecg.modules.gongqiang.entity.SerialNumber::getStatus, 1);
		org.jeecg.modules.gongqiang.entity.SerialNumber temp=new org.jeecg.modules.gongqiang.entity.SerialNumber();
		temp.setStatus(2);
		serialNumberMapper.update(temp,querySerialNumber);
	}
}
